package com.cn.book;

import java.io.IOException;
import java.net.*;

public class UDPPost {
    public static void main(String[] args) throws IOException {
        //建立通道
        DatagramSocket socket = new DatagramSocket();

        //打包数据
        String str = "我是要发送的数据。。。";
        byte[] bts = str.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");
        int port = 10010;
        DatagramPacket packet = new DatagramPacket(bts, bts.length, address, port);

        //发送数据
        socket.send(packet);

        //释放资源
        socket.close();
    }
}
